package com.symaster.common.test;

import java.awt.*;

/**
 * @author yinmiao
 * @version 2023/11/23
 */
public class ColorTest1 {

    public static void main(String[] args) {

        int[] rgba1 = new int[]{45, 45, 23, 255};
        int[] rgba2 = new int[]{66, 35, 23, 255};

        Color color = colorMix(new Color(45, 45, 23, 255), new Color(66, 35, 23, 0));

        System.out.println(color);
    }

    public static Color colorMix(Color c1, Color c2) {

        int alpha1 = c1.getAlpha();
        int alpha2 = c2.getAlpha();

        float v = (float) alpha1 / (alpha1 + alpha2);

        int r = colorMix(c1.getRed(), c2.getRed(), v);
        int g = colorMix(c1.getGreen(), c2.getGreen(), v);
        int b = colorMix(c1.getBlue(), c2.getBlue(), v);

        return new Color(r, g, b, Math.min(c1.getAlpha() + c2.getAlpha(), 255));
    }

    public static int colorMix(int c1, int c2, float scale) {
        int max = Math.max(c1, c2);
        int min = Math.min(c1, c2);

        if (max - min <= 0) {
            return c1;
        }
        return Math.min(Math.round((max - min) / (scale) + c1), 255);
    }


}
